#!/usr/bin/env python
import os
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
from google.appengine.dist import use_library
use_library('django', '1.2')

from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from django.utils import simplejson
from model import StudentM

class getStudentVotesHandler(webapp.RequestHandler):
    def get(self):
        topicKey = self.request.get("topicKey")
        
        if topicKey:
            result = StudentM.getStudentVotesStats(topicKey)
            if isinstance(result, basestring): #Error
                self.response.out.write(result)
            elif result:
                self.response.out.write(simplejson.dumps(result))
        else:
            pass

application = webapp.WSGIApplication([(r'.*', getStudentVotesHandler)],debug=True)

def main():
    run_wsgi_app(application)
    
if __name__ == '__main__':
    main()